﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using XH.DataUpload.Entities;
using XH.DataUpload.Logger;

namespace XH.DataUpload.ORM
{
    public class XHDbContext : DbContext
    {
        public XHDbContext(DbContextOptions<XHDbContext> options)
            : base(options)
        { }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            // EFCore的数据库执行日志，可以跟踪时使用
            optionsBuilder.LogTo(message =>
            {
                LogQueue.ORMLogQueue.Enqueue(message);
            });

            if (!optionsBuilder.IsConfigured)
                optionsBuilder.UseSqlite("Data Source=DataUploadDB.db");
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            base.OnModelCreating(modelBuilder);
        }

        // 数据库对应的实体类
        public virtual DbSet<SysUser> SysUser { get; set; }
    }
}
